<?php

namespace App\Jobs;

use App\Models\FlowChannel;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class CheckOrderRecord implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    private $check_order_info = '';

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($check_order_info)
    {
        $this->check_order_info = $check_order_info;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $check_order_info = unserialize($this->check_order_info);
        $time = Carbon::createFromTimestamp($check_order_info['time']);
        try {
            \App\Models\CheckOrderRecord::query()->create([
                'check_order_id' => $check_order_info['check_order_id'],
                'flow_channel_id' => $check_order_info['flow_channel_id'],
                'ip' => $check_order_info['ip'],
                'date' => $time->toDateString(),
                'hour' => $time->hour,
            ]);
        } catch (\Exception $exception) {

            Log::error('队列任务-》检测订单数据存入redis失败：' . $exception->getMessage() . $this->check_order_info);
        }

    }
}
